package com.luke.web.controller.base;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.luke.common.utils.SecurityUtils;
import com.luke.common.utils.ServletUtils;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luke.common.annotation.Log;
import com.luke.common.core.controller.BaseController;
import com.luke.common.core.domain.AjaxResult;
import com.luke.common.enums.BusinessType;
import com.luke.base.domain.LkProblem;
import com.luke.base.service.ILkProblemService;
import com.luke.common.utils.poi.ExcelUtil;
import com.luke.common.core.page.TableDataInfo;

/**
 * 问题反馈Controller
 * 
 * @author luke
 * @date 2021-06-02
 */
@RestController
@RequestMapping("/base/problem")
public class LkProblemController extends BaseController
{
    @Autowired
    private ILkProblemService lkProblemService;

    /**
     * 查询问题反馈列表
     */
    @PreAuthorize("@ss.hasPermi('base:problem:list')")
    @GetMapping("/list")
    public TableDataInfo list(LkProblem lkProblem)
    {
        startPage();
        List<LkProblem> list = lkProblemService.selectLkProblemList(lkProblem);
        return getDataTable(list);
    }

    /**
     * 导出问题反馈列表
     */
    @PreAuthorize("@ss.hasPermi('base:problem:export')")
    @Log(title = "问题反馈", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LkProblem lkProblem)
    {
        List<LkProblem> list = lkProblemService.selectLkProblemList(lkProblem);
        ExcelUtil<LkProblem> util = new ExcelUtil<LkProblem>(LkProblem.class);
        return util.exportExcel(list, "问题反馈数据");
    }

    /**
     * 获取问题反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:problem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lkProblemService.selectLkProblemById(id));
    }

    /**
     * 新增问题反馈
     */
    @PreAuthorize("@ss.hasPermi('base:problem:add')")
    @Log(title = "问题反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LkProblem lkProblem)
    {
        return toAjax(lkProblemService.insertLkProblem(lkProblem));
    }

    /**
     * 修改问题反馈
     */
    @PreAuthorize("@ss.hasPermi('base:problem:edit')")
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LkProblem lkProblem)
    {
        return toAjax(lkProblemService.updateLkProblem(lkProblem));
    }
    /**
     * 修改问题反馈
     */
    @PreAuthorize("@ss.hasPermi('base:problem:edit')")
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/answerProblem")
    public AjaxResult answerProblem(@RequestBody LkProblem lkProblem)
    {
        lkProblem.setAnswerTime(new Date());
        lkProblem.setHandleStatus("1");
        return toAjax(lkProblemService.updateLkProblem(lkProblem));
    }
    /**
     * 修改问题反馈
     */
    @PreAuthorize("@ss.hasPermi('base:problem:edit')")
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/handleProblem")
    public AjaxResult handleProblem(@RequestBody LkProblem lkProblem)
    {
        lkProblem.setAnswerContent(null);
        lkProblem.setConfirmStatus(null);
        lkProblem.setHandleTime(new Date());
        lkProblem.setHandleStatus("2");
        return toAjax(lkProblemService.updateLkProblem(lkProblem));
    }

    /**
     * 删除问题反馈
     */
    @PreAuthorize("@ss.hasPermi('base:problem:remove')")
    @Log(title = "问题反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lkProblemService.deleteLkProblemByIds(ids));
    }
}
